package com.example.mvp.presenter;

import android.os.Handler;

import com.example.mvp.model.IUserBiz;
import com.example.mvp.model.OnLoginListener;
import com.example.mvp.model.entity.User;
import com.example.mvp.view.IUserLoginView;



/**
 * Created by r on 2017/5/23.
 */

public class UserLoginPresenter {
    private IUserBiz mIUserBiz;
    private IUserLoginView mIUserLoginView;
    private Handler mHandler=new Handler();

    public UserLoginPresenter(IUserLoginView mIUserLoginView) {
        this.mIUserLoginView = mIUserLoginView;
        this.mIUserBiz = new IUserBiz();
    }
    public void login(){
        mIUserLoginView.showLoding();
        mIUserBiz.loginModel(mIUserLoginView.getUsername(), mIUserLoginView.getUserpwd(), new OnLoginListener() {
            @Override
            public void loginSuccess(User user) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                       mIUserLoginView.toSuccessActivity();
                        mIUserLoginView.hideLoding();
                    }
                });
            }

            @Override
            public void loginFaild() {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mIUserLoginView.showFailedError();
                        mIUserLoginView.hideLoding();
                    }
                });
            }
        });
    }
    public void clear(){
        mIUserLoginView.clearUsername();
        mIUserLoginView.clearUserpwd();
    }
}
